﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Klinkby.Scheduler
{
    /// <summary>
    /// Specifies a minute on an hourly basis for <see cref="Scheduler"/>.
    /// </summary>
    [Serializable]
    public class HourlyInterval : MarshalByRefObject, IInterval
    {
        readonly int _minutesInHour;

        public HourlyInterval(int minutesInHour)
        {
            if (minutesInHour >= 60)
                throw new ArgumentException("Must be less than 60 minutes", "minutesInHour");
            _minutesInHour = minutesInHour;
        }

        #region IInterval Members

        public DateTime Next
        {
            get
            {
                var now = DateTime.Now;
                return new DateTime(
                    now.Year, 
                    now.Month, 
                    now.Day, 
                    now.Minute > _minutesInHour 
                        ? now.Hour + 1 
                        : now.Hour, 
                    _minutesInHour,
                    0);
            }
        }

        #endregion
    }

}
